#include <func.h>

void exit_handler1(void)
{
    printf("I am going to die...\n");
}

void exit_handler2(int status, void* args)
{
    char* name = (char*) args;
    printf("Exit code: %d, Goodbye bye %s\n", status, name);
}

int main(int argc, char* argv[])
{
    // 1. 注册退出处理程序
    if (atexit(exit_handler1)) {
        fprintf(stderr, "at_exit() error\n");
        exit(1);
    }

    if (atexit(exit_handler1)) {
        fprintf(stderr, "at_exit() error\n");
        exit(1);
    }

    if (on_exit(exit_handler2, "Allen")) {
        fprintf(stderr, "at_exit() error\n");
        exit(1);
    }

    if (on_exit(exit_handler2, "Beyonce")) {
        fprintf(stderr, "at_exit() error\n");
        exit(1);
    }

    printf("Begin\n");
    // ...
    printf("End\n");
    exit(54);
    // _exit(0);
}

